//
//  GlobalInfo.m
//  upnpxdemo
//
//  Created by 赵帅 on 13-9-1.
//  Copyright (c) 2013年 wiimu.inc. All rights reserved.
//

#import "GlobalInfo.h"
#import "OpenUDID.h"
#import "FCUUID.h"

@implementation GlobalInfo
//@synthesize currentSelectedUpnP;
@synthesize currentBaseURL;
@synthesize currentSelectedUpnPInfo;
@synthesize errorCount;
@synthesize isVersionNew;
@synthesize deviceType;
@synthesize isDisconnect;
//@synthesize m_CmdSock;

@synthesize tempHttpHost, tempHttpPort;

static GlobalInfo *sharedObj = nil;

+(GlobalInfo*)sharedInstance{
    if (sharedObj == nil) {
        sharedObj = [[super allocWithZone:NULL]init];
        [sharedObj setIsVersionNew:NO];
        sharedObj.errorCount = 0;
        sharedObj.sql_queue = dispatch_queue_create("wiimu.com", NULL);
    }
    return sharedObj;
}

+ (id)allocWithZone:(NSZone *)zone{
    return [self sharedInstance];//返回单例
}

- (id)copyWithZone:(NSZone*)zone{
    return self;
}

-(void)setIsVersionNew:(BOOL)version
{
    isVersionNew = version;
    [[NSNotificationCenter defaultCenter] postNotificationName:@"NewVersionCome" object:nil];
}

-(void)addWifiInfo:(NSString *)name password:(NSString *)pass
{
    NSMutableDictionary * wifiListDic = [NSMutableDictionary dictionaryWithDictionary:[[NSUserDefaults standardUserDefaults] dictionaryForKey:@"WifiList"]];
    
    [wifiListDic setObject:pass forKey:name];
    
    [[NSUserDefaults standardUserDefaults] setObject:wifiListDic forKey:@"WifiList"];
}

-(NSString *)getWifiPassword:(NSString *)name
{
    NSMutableDictionary * wifiListDic = [NSMutableDictionary dictionaryWithDictionary:[[NSUserDefaults standardUserDefaults] dictionaryForKey:@"WifiList"]];
    NSString * ret = [wifiListDic objectForKey:name];
    return ret?ret:@"";
}

-(BOOL)isMusicDeleteFile
{
    return [[NSUserDefaults standardUserDefaults] boolForKey:@"DeleteMusic"];
}

-(void)setMusicDeleteFile:(BOOL)deleteFile
{
    [[NSUserDefaults standardUserDefaults] setBool:deleteFile forKey:@"DeleteMusic"];
}


-(NSString *)getUniqueID
{
    //    NSString *adId = [[[ASIdentifierManager sharedManager] advertisingIdentifier] UUIDString];
    //
    //    NSMutableString * mutableString = [NSMutableString stringWithString:adId];
    //    [mutableString replaceOccurrencesOfString:@"-" withString:@"" options:NSCaseInsensitiveSearch range: NSMakeRange(0, [mutableString length])];
    //
    //    return mutableString;
    
    NSString* openUDID = [FCUUID uuidForDevice];//[OpenUDID value];
    NSString * retStr = [NSString stringWithFormat:@"ios%@",[openUDID substringToIndex:28]];
 #if (TARGET_IPHONE_SIMULATOR)
    retStr = FIXED_UUID;
 #endif
    return retStr;
}

- (NSString *)tempHttpHost {
    return @"183.238.163.181";
}

- (NSInteger)tempHttpPort {
    return 1165;
}

+ (BOOL)isRunOnDevice {
    //注意不要用＃ifdef TARGET_IPHONE_SIMULATOR, 因为在device上， TARGET_IPHONE_SIMULATOR被定义为0
#if TARGET_IPHONE_SIMULATOR
    return FALSE;
#else
    return TRUE;
#endif
}

@end